package markgame2d.engine.mover;

import markgame2d.engine.MarkMath;
import markgame2d.engine.interfaces.Moveable;

public class MarkConstantCircleMover implements MarkMover{

	public Moveable moveable;
	public Moveable toFollow;
	public int radius;
	public float angularVel;//rotacoes por segundo
	
	private float currentAngle;
	
	public MarkConstantCircleMover(Moveable moveable, Moveable toFollow, int radius, float angularVel, float startAngle) {
		this.moveable = moveable;
		this.toFollow = toFollow;
		this.radius = radius;
		this.angularVel = angularVel;
		
		this.currentAngle = startAngle;
	}
	
	public Moveable getMoveable() {
		return moveable;
	}
	public void setMoveable(Moveable moveable) {
		this.moveable = moveable;
	}
	
	private void updateMoveablePosition(){
		float x = toFollow.getCenterX() + radius * MarkMath.cos(currentAngle);
		float y = toFollow.getCenterY() + radius * MarkMath.sin(currentAngle);
		moveable.centerOnXY(x,y);
	}
	
	public void move(float time) {
		currentAngle += angularVel * time;
		
		currentAngle %= MarkMath.TWO_PI;
		
		updateMoveablePosition();
	}
	
}
